//
//  OrderRootCell.m
//  zhiche--delivery
//
//  Created by LeeBruce on 16/5/27.
//  Copyright © 2016年 LeeBruce. All rights reserved.
//

#import "OrderRootCell.h"
#import <Masonry.h>

#define marWidth 90 * kWidth

@implementation OrderRootCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self initSubViews];
        
    }
    
    return  self;
}

-(void)initSubViews
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, cellHeight)];
    view.backgroundColor = headerBottomColor;
    [self.contentView addSubview:view];
    
    UILabel *numberL = [[UILabel alloc]initWithFrame:CGRectMake(18 , 0, 45 * kWidth, cellHeight)];
    [view addSubview:numberL];
    numberL.font = Font(12);
    numberL.textColor = littleBlackColor;
    numberL.text = @"运单号:";
    
    
    //订单编号
    self.orderNumberL = [self backLabelWithFrame:CGRectMake(CGRectGetMaxX(numberL.frame) , 0, 200, cellHeight) andFont:12];
    self.orderNumberL.text = @"";
    self.orderNumberL.textAlignment = NSTextAlignmentLeft;
    self.orderNumberL.textColor = littleBlackColor;

    [view addSubview:self.orderNumberL];
    
  
//    //用时label
//    self.timeL = [self backLabelWithFrame:CGRectMake(screenWidth - 14 - 50, 0,50 * kWidth,cellHeight) andFont:12];
//    self.timeL.text = @"20分钟";
//    self.timeL.textColor = RedColor;
//    [view addSubview:self.timeL];
    

//    UIImageView *timeImage = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.timeL.frame) - 7, (cellHeight - 15)/2.0, 15, 15)];
//    timeImage.backgroundColor = [UIColor cyanColor];
//    [view addSubview:timeImage];
//    timeImage.image = [UIImage imageNamed:@"quote_cell_time"];
    
    self.statusLabel = [self backLabelWithFrame:CGRectMake(screenWidth - 14 - 90 * kWidth, (cellHeight - 15 * kHeight)/2.0 ,50 * kWidth,15 * kHeight) andFont:12];
    self.statusLabel.layer.cornerRadius = 5;
    self.statusLabel.textColor = RedColor;
    self.statusLabel.backgroundColor = WhiteColor;
    [view addSubview:self.statusLabel];
    
    
    self.status = [self backLabelWithFrame:CGRectMake(CGRectGetMaxX(self.statusLabel.frame), (cellHeight - 15 * kHeight)/2.0, 50 * kWidth, 15 * kWidth) andFont:12];
    self.status.layer.cornerRadius = 5;
    self.status.textColor = RedColor;
    self.status.backgroundColor = WhiteColor;
    [view addSubview:self.status];

    
    
    
    
    __weak typeof(self) weakSelf = self;

    
    UILabel *lineL1 = [[UILabel alloc]init];
    [self.contentView addSubview:lineL1];
    [lineL1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(weakSelf.orderNumberL.mas_bottom).offset(0);
        make.centerX.equalTo(weakSelf.contentView);
        make.size.mas_equalTo(CGSizeMake(screenWidth , 0.5));
    }];
    
    lineL1.backgroundColor = LineGrayColor;

    
    //起始地址
    self.startAddress = [[UILabel alloc]init];
    [self.contentView addSubview:self.startAddress];
    [self.startAddress mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(view.mas_bottom).offset(10 * kHeight);
        
        make.left.mas_equalTo(10 * kWidth);
        
        make.size.mas_equalTo(CGSizeMake(marWidth, 40 * kHeight));
        
    }];
    self.startAddress.textAlignment = NSTextAlignmentCenter;
    self.startAddress.font = Font(13);
    self.startAddress.textColor = littleBlackColor;
    self.startAddress.text = @"";
    self.startAddress.numberOfLines = 0;
    
    //终止地址
    self.endAddress = [[UILabel alloc]init];
    [self.contentView addSubview:self.endAddress];
    [self.endAddress mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(view.mas_bottom).offset(10 * kHeight);
        make.right.mas_equalTo(-10 * kWidth);
        make.size.mas_equalTo(CGSizeMake(marWidth, 40 * kHeight));
        
    }];
    self.endAddress.textAlignment = NSTextAlignmentCenter;
    self.endAddress.font = Font(13);
    self.endAddress.textColor = littleBlackColor;
    self.endAddress.numberOfLines = 0;
    
    self.endAddress.text = @"";


    //起始时间
    
    self.startTimeL = [[UILabel alloc]init];
    [self.contentView addSubview:self.startTimeL];
    [self.startTimeL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(weakSelf.startAddress.mas_bottom).offset(4 * kHeight);
        make.left.mas_equalTo(10 * kWidth);
        make.size.mas_equalTo(CGSizeMake(marWidth, 12 * kHeight));
        
    }];
    self.startTimeL.textAlignment = NSTextAlignmentCenter;
    self.startTimeL.font = Font(10);
    self.startTimeL.textColor = littleBlackColor;
    
    self.startTimeL.text = @"";
    
    
    //终止时间
    self.endTimeL = [[UILabel alloc]init];
    [self.contentView addSubview:self.endTimeL];
    [self.endTimeL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(weakSelf.startAddress.mas_bottom).offset(4 * kHeight);
        make.right.mas_equalTo(-10 * kWidth);
        make.size.mas_equalTo(CGSizeMake(marWidth, 12 * kHeight));
        
    }];
    self.endTimeL.textAlignment = NSTextAlignmentCenter;
    self.endTimeL.font = Font(10);
    self.endTimeL.textColor = littleBlackColor;
    
    self.endTimeL.text = @"";

    
    /*
    //起始详情地址
    self.startDetailAddress = [[UILabel alloc]init];
    self.startDetailAddress.adjustsFontSizeToFitWidth = YES;
    [self.contentView addSubview:self.startDetailAddress];
    [self.startDetailAddress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.startAddress.mas_bottom).offset(0 * kHeight);
        make.centerX.equalTo(weakSelf.startAddress);
        make.size.mas_equalTo(CGSizeMake(marWidth, 28 * kHeight));
    }];
    self.startDetailAddress.textAlignment = NSTextAlignmentCenter;
    self.startDetailAddress.font = Font(9);
    self.startDetailAddress.textColor = littleBlackColor;
    self.startDetailAddress.numberOfLines = 0;
    self.startDetailAddress.text = @"北京八大处北京八大处";
       
    //终止详情地址
    self.endDetailAddress = [[UILabel alloc]init];
    self.endDetailAddress.adjustsFontSizeToFitWidth = YES;
    [self.contentView addSubview:self.endDetailAddress];
    [self.endDetailAddress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.endAddress.mas_bottom).offset(0 * kHeight);
        make.centerX.equalTo(weakSelf.endAddress);
        make.size.mas_equalTo(CGSizeMake(marWidth, 28 * kHeight));
        
        
    }];
    self.endDetailAddress.textAlignment = NSTextAlignmentCenter;
    self.endDetailAddress.font = Font(9);
    self.endDetailAddress.textColor = littleBlackColor;
    self.endDetailAddress.text = @"杭州西湖";
    self.endDetailAddress.numberOfLines = 0;
    */
     
    
    
    UIImageView *imageV = [[UIImageView alloc]init];
    imageV.image = [UIImage imageNamed:@"Quote_Cell_logo"];
    [self.contentView addSubview:imageV];
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.equalTo(weakSelf.contentView);
        make.centerY.equalTo(weakSelf.startAddress).offset(11 * kHeight);
        
        make.size.mas_equalTo(CGSizeMake(47, 12.5));
        
    }];
    
    
    
    UILabel *lineL2 = [[UILabel alloc]init];
    [self.contentView addSubview:lineL2];
    [lineL2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(weakSelf.startTimeL.mas_bottom).offset(10 * kHeight);
        make.centerX.equalTo(weakSelf.contentView);
        make.size.mas_equalTo(CGSizeMake(screenWidth , 0.5));
    }];
    
    lineL2.backgroundColor = LineGrayColor;
    
    
//    self.scroll = [[UIScrollView alloc]init];
//    [self.contentView addSubview:self.scroll];
//    [self.scroll mas_makeConstraints:^(MASConstraintMaker *make) {
//       
//        make.top.mas_equalTo(lineL2.mas_bottom).offset(0);
//        make.left.mas_equalTo(20 );
//        make.size.mas_equalTo(CGSizeMake(screenWidth - 40, cellHeight));
//
//    }];
//    self.scroll.contentSize = CGSizeMake(screenWidth + 100, cellHeight);
//    self.scroll.alwaysBounceHorizontal = YES;
//    self.scroll.showsHorizontalScrollIndicator = NO;
//    
    
    //车型
    self.carStyleL = [[UILabel alloc]init];
    [self.contentView addSubview:self.carStyleL];
    [self.carStyleL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(lineL2.mas_bottom).offset(0);
        make.left.mas_equalTo(20);
        make.size.mas_equalTo(CGSizeMake(screenWidth - 40, cellHeight));
        
    }];
    
    self.carStyleL.font = Font(13);
    self.carStyleL.textColor = littleBlackColor;
//    self.carStyleL.text = @"沃尔沃XC90  沃尔沃V60 ";
    
    UILabel *lineL3 = [[UILabel alloc]init];
    [self.contentView addSubview:lineL3];
    [lineL3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(weakSelf.carStyleL.mas_bottom).offset(0);
        make.centerX.equalTo(weakSelf.contentView);
        make.size.mas_equalTo(CGSizeMake(screenWidth , 0.5));
    }];
    
    lineL3.backgroundColor = LineGrayColor;
    
    self.lastView = [[UIView alloc]init];
    self.lastView.backgroundColor = headerBottomColor;
    [self.contentView addSubview:self.lastView];
    [self.lastView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(lineL3.mas_bottom).offset(0);
        make.size.mas_equalTo(CGSizeMake(screenWidth, cellHeight));
        
    }];
    
        
    
}

-(UILabel *)backLabelWithFrame:(CGRect)frame andFont:(int)a
{
    UILabel *label = [[UILabel alloc]init];
    label.frame = frame;
    label.textAlignment = NSTextAlignmentCenter;
    label.font = Font(a);
    [self.contentView addSubview:label];
    
    return  label;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
